var t = getApp(), e = t.requirejs("core"), a = t.requirejs("foxui"), i = t.requirejs("biz/diyform"), n = t.requirejs("jquery");
const app=getApp();
Page({
    data: {
        icons: t.requirejs("icons"),
        member: {},
        diyform: {},
        postData: {},
        openbind: !1,
        index: 0,
        submit: !1,
        showPicker: !1,
        pvalOld: [ 0, 0, 0 ],
        pval: [ 0, 0, 0 ],
        areas: [],
        noArea: 0,
        cateIndex: 0,
        tempFilePaths: "",
        images: [],
        imgs: []
    },
    onLoad: function(e) {
        t.url(e);
        t.getSet();
        t.checkAuth();
        var a = this;
        setTimeout(function() {
            a.setData({
                areas: t.getCache("cacheset").areas
            });
        }, 1e3);
        app.globalData.Flag = true;
        //e.checkAuth();
    },
    onShow: function() {
        if(app.globalData.Flag){
         app.globalData.Flag = false;
         this.getInfo();
        }

    },
    getInfo: function() {
        var t = this;
        e.get("abonus/register", {}, function(e) {
            var a = e.member, i = {
                set:e.set,
                member: a,
                diyform: e.diyform,
                openbind: e.openbind,
                show: !0
            };
            console.log('--------------e');
            console.log(e);
             i.postData = {              
                realname: a.realname,
                nickname: a.nickname,
                mobile: a.mobile,
                avatar: a.avatar,
                weixin: a.weixin,
                birthday: a.birthday,
                city: a.city
            }, t.setData(i);
            console.log('--------------t');
            console.log(t.data);
        });
    },
    onChange: function(t) {
        var a = t.detail.value, i = e.pdata(t).type, r = this.data.postData;
        r[i] = n.trim(a), this.setData({
            postData: r
        });
    },
    DiyFormHandler: function(t) {
        return i.DiyFormHandler(this, t);
    },
    upload: function (e1) {
        var that = this;
        var i = e.data(e1), r = i.type, s = that.data.images, n = that.data.imgs, m = i.index;
        console.log(that.data);
        "image" == r ? e.upload(function (e) {
          if (n.length ==0){

              s.push(e.filename), n.push(e.url), that.setData({
              images: s,
              imgs: n,
              flash:false

              })
          }else{
            wx.showToast({
              title: '限制1张图片',
              icon: 'loading',
              duration: 1000
            });
          }
        }) : "image-remove" == r ? (s.splice(m, 1), n.splice(m, 1), that.setData({
          images: s,
          imgs: n
        })) : "image-preview" == r && wx.previewImage({
          current: n[m],
          urls: n
        });

      },
    submit: function() {
        if (!this.data.submit) {
            var t = this, r = t.data, o = r.diyform;
            
            if (!r.postData.realname) return void a.toast(t, "请填写姓名");
            if (!n.isMobile(r.postData.mobile) ) return void a.toast(t, "请填写正确手机号码");
            if (!r.postData.city) return void a.toast(t, "请选择代理地区");
            t.setData({
                submit: !0
            });
            var s = {
                memberdata: r.postData,
                images: this.data.imgs,
            };
             e.post("abonus/register", s, function(e) {
                0 == e.error ? (t.setData({
                    submit: !1
                }), a.toast(t, "提交成功"), setTimeout(function() {
                    wx.navigateBack();
                }, 500)) : a.toast(t, e.message);
            });
        }
    },
    selectArea: function(t) {
        return i.selectArea(this, t);
    },
    bindChange: function(t) {
        return i.bindChange(this, t);
    },
    onCancel: function(t) {
        return i.onCancel(this, t);
    },
    onConfirm: function(t) {
        
        var e = this.data.pval, a = this.data.areas, n = this.data.postData;
        console.log(e);console.log(a);console.log(n);
        n.city = a[e[0]].name + " " + a[e[0]].city[e[1]].name+ " " + a[e[0]].city[e[1]].area[e[2]].name, this.setData({
            postData: n,
            showPicker: !1
        });
    },
    getIndex: function(t, e) {
        return i.getIndex(t, e);
    }
});